{% extends "djangovoice/feedback_base.html" %}

{% load voting_tags %}
{% load gravatar %}
{% load comments %}

{% block title %}{{ title }}{% endblock %}

{% block sidebar %}
    {% include "djangovoice/sidebar.html" %}
{% endblock %}

{% block content %}
<h1>{{ title }}</h1>

{% if feedback_list %}
    {% votes_by_user user on feedback_list as vote_dict %}
    {% scores_for_objects feedback_list as score_dict %}

    <table class="list">
    {% for feedback in feedback_list %}

        {% dict_entry_for_item feedback from vote_dict as vote %}
        {% dict_entry_for_item feedback from score_dict as score %}
        
        {% get_comment_count for feedback as comment_count %}
        
        <tr>
            <td class="votes"><div>{{ score.score|default:0 }}</div></td>
            <td class="status"><span class="feedback-type feedback-type-{{ feedback.type.slug }}">{{ feedback.type.title }}</span></td>
            <td class="details"><h3><a href="{{ feedback.get_absolute_url }}">{{ feedback.title }}</a> <span class="feedback-status feedback-status-{{ feedback.status.slug }}">{{ feedback.status.title }}</span></h3><p> <span class="feedback-comments"><a href="{{ feedback.get_absolute_url }}">{{ comment_count }} comment{{ comment_count|pluralize }}</a></span> <span class="feedback-user">{% if feedback.user %}Submitted by: <a href="{{ feedback.user.get_absolute_url }}" class="avatar" title="View profile">{% gravatar feedback.user.username 15 %}</a> <a href="{{ feedback.user.get_absolute_url }}" title="View profile">{{ feedback.user }}</a>{% else %}Submitted anonymously</span>{% endif %} <span class="feedback-date">on {{ feedback.created|date:"d M Y" }}</span></p></td>
            {% if feedback.private %}
                <td class="feedback-private">PRIVATE</td>
            {% endif %}
        </tr>
    {% endfor %}
    </table>

    <div class="pagination">
        <span class="step-links">
            {% if pagination.has_previous %}
                <a href="?page=1" id="pagination-first-page">&laquo; {% trans "first" %}</a>
                <a href="?page={{ pagination.previous_page_number }}" id="pagination-previous-page">&larr; {% trans "previous" %}</a>
            {% endif %}

            <span class="current">
                {% trans "Page" %} {{ pagination.number }} {% trans "of" %} {{ pagination.paginator.num_pages }}
            </span>

            {% if pagination.has_next %}
                <a href="?page={{ pagination.next_page_number }}" id="pagination-next-page">{% trans "next" %} &rarr;</a>
                <a href="?page={{ pagination.paginator.num_pages }}" id="pagination-last-page">{% trans "last" %} &raquo;</a>
            {% endif %}
        </span>
    </div>

{% else %}
    <p>No-one has contributed any feedback yet. Be the first and <a href="{% url djangovoice_submit %}">submit some feedback</a>!</p> 
{% endif %}
{% endblock %}
